<?php

namespace app\api\controller;

use app\api\model\GoodsModel;
use app\api\model\OrderModel;
use app\api\service\Token;
use app\api\validate\IDMustBePositiveInt;
use think\Cache;
use think\Controller;
use app\api\service\Order as OrderService;
use think\Request;

class Order extends BaseController
{
    // 用户订单表
    public function orderList()
    {
        $data = request()->param();
        $where = [];
        if (!empty($data['status'])){
            $where['status']=$data['status'];
        }
        $order = new OrderModel();
        $uid = Token::getCurrentTokenVar('uid');
        $flag = $order->getOrderList($where,$uid);
        return json($flag);
    }

    //生成订单
    public function createOrder()
    {
        $goods_id = input('param.id');
        (new IDMustBePositiveInt())->goCheck();
        $uid = Token::getCurrentTokenVar('uid');
        $goods = GoodsModel::getOneGoods($goods_id);
        $goods['goods_id']=$goods_id;
        $goods['uid'] = $uid;
        $goods['order_num'] = OrderService::makeOrderNo();
        $goods['add_time'] = time();
        $order = new OrderModel();
        $flag = $order->createOrder($goods);
        return json($flag);
    }

    //订单详情
    public function orderDetail()
    {
        (new IDMustBePositiveInt())->goCheck();
        $order_id = input('param.id');
        $uid = Token::getCurrentTokenVar('uid');
        $data = OrderModel::getOneOrder($order_id,$uid);
        return json(msg(1,$data,'查询订单成功'));
    }




//    public function cs()
//    {
////        $param = Request::instance()->get(['tel']);var_dump($param);die;
////        $res = Cache::store('redis')->clear();var_dump($res);die;
//        require (EXTEND_PATH.'bdxcxpay/pay/rsasigndemo.php');
//        $rsa = new \rsasigndemo();
//        $data = $rsa->createRsa('201812020924','4');
//        var_dump($data);
//
//    }
}
